﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace EvePoint.Library.HtmlControls
{
    public class ViewportManager
    {

        public static void AddPageViewport(Viewport port, Page currentPage, bool updateViewPortIfExists)
        {
           HtmlHead head=currentPage.Header as HtmlHead;
           bool viewportAdded = true;

           if (head != null)
           {
               for (int i = head.Controls.Count; i > 0; i--)
               {
                   Control ctrl = head.Controls[i]; 
                   if (ctrl is Viewport)
                   {

                       if (updateViewPortIfExists)
                       {
                           head.Controls.RemoveAt(i); 
                           head.Controls.Add(port);

                       }

                       viewportAdded = false;
                       break;
                   }

               }


               //Add new viewpoert
               if (viewportAdded)
               {

                   head.Controls.Add(port); 
               }
           }


            



         
        }


    }

}
